//
//  MyInfoViewController.m
//  Mtime
//
//  Created by wang xinkai on 15/7/28.
//  Copyright (c) 2015年 wxk. All rights reserved.
//

#import "MyInfoViewController.h"
#import "MyView.h"

@implementation MyInfoViewController
{
    NSArray *_cellData1;//分组一的数据组
    NSArray *_imageArray;//分组一的图片数组
    NSArray *_cellData2;//分组二的数据组
}
-(id)init{
    
    if (self = [super init]) {
        
        self.title = @"我的";
        self.tabBarItem.image = [UIImage imageNamed:@"myinfo"];
        
        [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"home_top_movie_background_cover"]]];
        
    }
    return self;
    
}

- (void)viewDidLoad {

    [super viewDidLoad];
    
    [self loadData];
    
    [self reloadView];
}

-(void)loadData{
    
    _cellData1 = @[@"我去影院看电影",@"我的优惠卷",@"我的电影",@"我的收藏"];
    
    _cellData2 = @[@"设置",@"扫描二维码",@"意见反馈",@"喜欢我们，去打分",@"商城使用帮助"];
    
    UIImage *image1 = [UIImage imageNamed:@"icon_my_cinema"];
    UIImage *image2 = [UIImage imageNamed:@"icon_my_coupon"];
    UIImage *image3 = [UIImage imageNamed:@"icon_my_movie"];
    UIImage *image4 = [UIImage imageNamed:@"icon_my_collection"];
    
    _imageArray = @[image1,image2,image3,image4];


}


- (void)reloadView {

    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH -64)];
    
    tableView.backgroundColor = [UIColor clearColor];
    
    tableView.delegate = self;
    tableView.dataSource = self;
    
    [self.view addSubview:tableView];

    MyView *headerView = [[[NSBundle mainBundle] loadNibNamed:@"View" owner:nil options:nil] lastObject];
    
    headerView.backgroundColor = [UIColor redColor];
    
    tableView.tableHeaderView = headerView;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 2;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (section == 0) {
        
        return _cellData1.count;
    }
    
    return _cellData2.count;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell1"];
    cell1.backgroundColor = [UIColor clearColor];
    
    UITableViewCell *cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell2"];
    cell2.backgroundColor = [UIColor clearColor];
    
    if (indexPath.section == 0) {
        
        cell1.imageView.image = _imageArray[indexPath.row];
        cell1.textLabel.text = _cellData1[indexPath.row];
        
        return cell1;
        
    }else {
        
        cell2.textLabel.text = _cellData2[indexPath.row];
        return cell2;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 20;
}


@end
